//
//  HNSH_SearchGoodsHeader.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/24.
//

#import "HNSH_SearchGoodsHeader.h"

@interface HNSH_SearchGoodsHeader ()
/** 标题 */
@property (nonatomic, strong) UILabel * titleLabel;
/** 删除按钮 */
@property (nonatomic, strong) UIButton * delBtn;
@end

@implementation HNSH_SearchGoodsHeader

//MARK: Cycle Methods
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor appWhiteLabelColor];
        [self addAllViews];
        [self addAllLayout];
    }
    return self;
}

- (void)addAllViews{
    [self addSubview:self.titleLabel];
    [self addSubview:self.delBtn];
}

- (void)addAllLayout{
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.height.mas_equalTo(self);
    }];
    [self.delBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.top.height.mas_equalTo(self);
        make.width.mas_equalTo(60);
    }];
}

//MARK: Myself Methods
- (void)delBtnAction{
    if (self.deleteBlock) {
        self.deleteBlock();
    }
}

//MARK: Getter Methods
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.textColor = [UIColor appBlackLabelColor];
        _titleLabel.font = [UIFont boldSystemFontOfSize:16];
        _titleLabel.text = @"历史搜索";
    }
    return _titleLabel;
}

- (UIButton *)delBtn{
    if (!_delBtn) {
        _delBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_delBtn setImage:[UIImage imageNamed:@"base_search_delete"] forState:UIControlStateNormal];
        [_delBtn addTarget:self action:@selector(delBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _delBtn;
}

@end
